#!/bin/bash

echo "========================================="
echo "Maven 安装脚本"
echo "========================================="
echo ""

# 下载Maven
echo "正在下载Maven 3.9.5..."
curl -L -o apache-maven-3.9.5-bin.tar.gz https://archive.apache.org/dist/maven/maven-3/3.9.5/binaries/apache-maven-3.9.5-bin.tar.gz

if [ $? -ne 0 ]; then
    echo "下载失败，请手动下载："
    echo "https://maven.apache.org/download.cgi"
    exit 1
fi

# 解压
echo "正在解压..."
tar -xzf apache-maven-3.9.5-bin.tar.gz

# 移动到/usr/local
echo "正在安装到 /usr/local/..."
sudo mv apache-maven-3.9.5 /usr/local/maven

# 配置环境变量
echo ""
echo "请将以下内容添加到 ~/.zshrc 文件："
echo ""
echo "export M2_HOME=/usr/local/maven"
echo "export PATH=\$M2_HOME/bin:\$PATH"
echo ""
echo "然后执行: source ~/.zshrc"
echo ""
echo "验证安装: mvn -version"
